<%@ page import="org.codehaus.groovy.grails.commons.ControllerArtefactHandler" %>
<!doctype html>
<%
    // todo this groovy code should not be in the GSP, can it be injected somewhere?

    String actionFullName = ""
    def controllerActions = new HashSet<String>()

    if (controllerName && controllerName != "index") {
        actionFullName = controllerName.toString().toLowerCase()
        actionFullName = actionFullName[0].toUpperCase() + actionFullName[1..-1]

        def controllerClass = grailsApplication
            .getArtefactInfo(ControllerArtefactHandler.TYPE)
            .getGrailsClassByLogicalPropertyName(controllerName)
        for (String uri : controllerClass?.uris ) {
            controllerActions.add(controllerClass?.getMethodActionName(uri) )
        }
        controllerActions = controllerActions?.sort() - "index"
    }
    if (actionName && actionName != "index") {
        actionFullName += "." + actionName
    }
%>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>
            ${grailsApplication.metadata['app.name']}
            <g:if test="${actionFullName}">|</g:if>
            ${actionFullName}
            <g:layoutTitle default=""/>
        </title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<link rel="shortcut icon" href="${resource(dir: 'images', file: 'favicon.ico')}" type="image/x-icon">
		<link rel="apple-touch-icon" href="${resource(dir: 'images', file: 'glickr_logo_057.png')}">
		<link rel="apple-touch-icon" sizes="114x114" href="${resource(dir: 'images', file: 'glickr_logo_114.png')}">
		<link rel="stylesheet" href="${resource(dir: 'css', file: 'main.css')}" type="text/css">
		<g:layoutHead/>
        <r:layoutResources />
	</head>
	<body>
		<div id="banner" role="banner">
                <a href="/${grailsApplication.metadata['app.name']}"><img src="${resource(dir: 'images', file: 'glickr_logo_057.png')}" alt="Glickr"/></a>
            <h1>
                ${grailsApplication.metadata['app.name']} ${grailsApplication.metadata['app.version']}
                <g:if test="${actionFullName}">/ ${actionFullName}</g:if>
            </h1>
            <ul id="controllers">
                <g:each var="c" in="${grailsApplication.controllerClasses.sort { it.fullName } }">
                    <li class="${c.name.toString().equalsIgnoreCase(controllerName)?'active':''}">
                        <g:link controller="${c.logicalPropertyName}">${c.name}</g:link>
                    </li>
                </g:each>
            </ul>
            <g:if test="${controllerActions.size() > 0}">
                <ul id="actions">
                    <g:each var="action" in="${controllerActions}">
                        <li class="${action.equalsIgnoreCase(actionName)?'active':''}">
                            <g:link action="${action}">${action}</g:link>
                        </li>
                    </g:each>
                </ul>
            </g:if>
        </div>
        <div class="layoutBody"><g:layoutBody/></div>
		<div id="spinner" class="spinner" style="display:none;"><g:message code="spinner.alt" default="Loading&hellip;"/></div>
		<g:javascript library="application"/>
        <r:layoutResources />
	</body>
</html>